#!/usr/bin/env python
# -*- coding:utf-8 -*-
import socketserver


class MyServer(socketserver.BaseRequestHandler):
    def handle(self):
        print("got connection from", self.client_address)
        while True:
            conn = self.request
            print("waiting for inputting...")
            send_str = input()
            conn.send(str.encode(send_str))
            data = conn.recv(1024)
            if not data:
                break
            try:
                print("------------", data.decode())
            except UnicodeDecodeError as e:
                print(e)
                continue
            print(self.client_address, str(data, 'utf8'))


if __name__ == '__main__':
    server = socketserver.ThreadingTCPServer(('172.31.100.250', 8090), MyServer)
    server.serve_forever()
